const express = require('express');
const path = require('path');
const app = express();
const bodyParser = require('body-parser');
const router = express.Router();

// 处理Json格式数据
app.use(bodyParser.json());
// 挂载参数处理中间件（post）
app.use(bodyParser.urlencoded({ extended: false }));

app.all('*', function(req, res, next){
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By",' 3.2.1');
    res.header("Content-Type", "application/json;charset=utf-8");
    next();
});

// app.use(router);
app.get('/img',(req,res)=>{
    var message = [
        {url:'http://www.baidu.com', img:'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1560844416368&di=4bfdfcc9f317a1fa0d3f8b22b2404462&imgtype=0&src=http%3A%2F%2Fs14.sinaimg.cn%2Fbmiddle%2F500b809744187b79887ed'},
        {url:'http://www.baidu.com', img:'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3510324684,128355022&fm=26&gp=0.jpg'}
    ];
    res.send({message:message}).end();
})


// 监听端口
app.listen(3001,()=>{
	console.log('running');
});